package com.clothing.utils.weixin;

import java.util.List;

import com.alibaba.fastjson.JSONObject;

public class TemplateMsg
{
    /** openId */
    private String touser;

    /** 模板Id */
    private String template_id;

    /** 跳转链接 */
    private String url;

    /** 推送数据 */
    private JSONObject data;

    public String getTouser()
    {
        return touser;
    }

    public void setTouser(String touser)
    {
        this.touser = touser;
    }

    public String getTemplate_id()
    {
        return template_id;
    }

    public void setTemplate_id(String template_id)
    {
        this.template_id = template_id;
    }

    public String getUrl()
    {
        return url;
    }

    public void setUrl(String url)
    {
        this.url = url;
    }

    public JSONObject getData()
    {
        return data;
    }

    public void setData(KeynoteItem first, KeynoteItem remark, List<KeynoteItem> keynotes)
    {
        JSONObject obj = new JSONObject();

        if (null != first)
        {
            obj.put("first", first);
        }

        if (null != remark)
        {
            obj.put("remark", remark);
        }

        JSONObject objSong = null;

        for (KeynoteItem keynoteItem : keynotes)
        {
            objSong = new JSONObject();
            objSong.put("color", keynoteItem.getColor());
            objSong.put("value", keynoteItem.getValue());
            obj.put(keynoteItem.getTagName(), objSong);
        }

        this.data = obj;
    }

    public String toJson()
    {
        JSONObject obj = new JSONObject();
        obj.put("touser", touser);
        obj.put("template_id", template_id);
        obj.put("url", url);
        obj.put("data", data);
        return obj.toJSONString();
    }

    public enum WeixinTemplate
    {
        COMMENT_MESSAGE(1, "留言评论提醒", "GMuVC_25JsAewgjYxfs1AJ3rb_8zB0QI-3sMt8BHwe4");

        private Integer code;

        private String description;

        private String codeName;

        private WeixinTemplate(Integer code, String description, String codeName)
        {
            this.code = code;
            this.description = description;
            this.codeName = codeName;
        }

        /**
         * 根据类型Code，获取枚举
         * 
         * @param code
         * @return weixinTemplate
         */
        public static WeixinTemplate getByCode(Integer code)
        {
            if (code == null)
            {
                return null;
            }
            for (WeixinTemplate weixinTemplate : values())
            {
                if (weixinTemplate.getCode() == code)
                    return weixinTemplate;
            }
            return null;
        }

        public Integer getCode()
        {
            return code;
        }

        public String getDescription()
        {
            return description;
        }

        public String getCodeName()
        {
            return codeName;
        }
    }
}
